﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" name="viewport" content="width=device-width" />
    <title>设备信息管理</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet" />
    <script src="../Content/scripts/jquery-1.11.1.min.js"></script>
    <link href="../Content/styles/font-awesome.min.css" rel="stylesheet" />
    <link href="../Content/scripts/plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet" />
    <script src="../Content/scripts/plugins/jquery-ui/jquery-ui.min.js"></script>
    <link href="../Content/scripts/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <script src="../Content/scripts/bootstrap/bootstrap.min.js"></script>
    <link href="../Content/scripts/plugins/jqgrid/jqgrid.css" rel="stylesheet" />
    <link href="../Content/styles/learun-ui.css" rel="stylesheet" />
    <script src="../Content/scripts/plugins/jqgrid/grid.locale-cn.js"></script>
    <script src="../Content/scripts/plugins/jqgrid/jqgrid.min.js"></script>
    <script src="../Content/scripts/plugins/tree/tree.js"></script>
    <script src="../Content/scripts/plugins/validator/validator.js"></script>
    <script src="../Content/scripts/utils/learun-ui.js"></script>
    <script src="../Content/scripts/utils/learun-form.js"></script>
    <script src="EquInfoJS.js"></script>
    <style type="text/css">
        body {
            margin: 10px;
            margin-bottom: 0px;
        }
    </style>
</head>
<body>
    <div class="titlePanel">
        <div class="title-search" id="search">
            <table>
                <tr>
                    <td style="padding-left: 5px;">
                        <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                    </td>
                    <td style="padding-left: 5px;">
                        <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                    </td>
                </tr>
            </table>
        </div>
        <div class="toolbar">
            <div class="btn-group">
                <a id="lr-add" class="btn btn-default" onclick="btn_add(event)"><i class="fa fa-plus"></i>&nbsp;新增</a>
                <a id="lr-edit" class="btn btn-default" onclick="btn_edit(event)"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                <a id="lr-fangsha" class="btn btn-default" onclick="btn_fangsha(event)"><i class="fa fa-pencil-square-o"></i>&nbsp;设置纺纱品种</a>
                <a id="lr-maintenance" class="btn btn-default" onclick="btn_maintenance(event)"><i class="fa fa-pencil-square-o"></i>&nbsp;设置维护周期</a>
                <a id="lr-weihu" class="btn btn-default" onclick="btn_weihu(event)"><i class="fa fa-pencil-square-o"></i>&nbsp;设备维护</a>
                <a id="lr-delete" class="btn btn-default" onclick="btn_delete(event)"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
            </div>

        </div>
    </div>
    <div class="gridPanel">
        <table id="gridTable"></table>
        <div id="gridPager"></div>
    </div>

    <script type="text/javascript">

        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 136.5);
            }, 200);
            e.stopPropagation();
        });

        $(function () {
            if (getCookie("CustomerID") !== "") {
                $("#lr-add").css('display', 'none');
                $("#lr-edit").css('display', 'none');
                $("#lr-delete").css('display', 'none');
                $("#search").css('display', 'none');
                $.equinfojs.initEquListByCustomerID(getCookie("CustomerName"));
            }
            else {
                $("#lr-fangsha").css('display', 'none');
                $("#lr-maintenance").css('display', 'none');
                $("#lr-weihu").css('display', 'none');
                $.equinfojs.initEquListByHongda(getCookie("CustomerName"));
            }
        })

        //查询事件
        $("#btn_Search").click(function () {

            $gridTable.jqGrid('setGridParam', {
                postData: {
                    Action: "GetEquTaiHaoInfo",
                    keyword: $("#txt_Keyword").val(),
                    CustomerName: getCookie("CustomerName")
                },
            }).trigger('reloadGrid');

        });

        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });


        //新增设备信息
        function btn_add(event) {

            dialogOpen({
                id: "Form",
                title: '新增设备信息',
                url: '../Equipment/EquipmentAdd.html',
                width: "400px",
                height: "400px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick($('#gridTable'));
                }
            });
        }


        // 编辑设备信息
        function btn_edit(event) {

            var EquNo = $("#gridTable").jqGridRowValue("EquNo");
            var Remark = $("#gridTable").jqGridRowValue("Remark");
            if (checkedRow(EquNo)) {
                dialogOpen({
                    id: "Form",
                    title: '编辑设备信息',
                    url: '../Equipment/EquipmentEdit.html?&EquNo=' + EquNo + '&Remark=' + Remark,
                    width: "400px",
                    height: "400px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].AcceptClick($('#gridTable'));
                    }
                });
            }

        }

        // 设置纺纱品种
        function btn_fangsha(event) {
            var TaiHao = $("#gridTable").jqGridRowValue("TaiHao");
            var EquNo = $("#gridTable").jqGridRowValue("EquNo");
            var FangShaKind = $("#gridTable").jqGridRowValue("FangShaKind");
            var CustomerID = $("#gridTable").jqGridRowValue("CustomerID");
            console.log(FangShaKind);
            if (checkedRow(TaiHao)) {
                dialogOpen({
                    id: "Form",
                    title: '设置纺纱品种--' + TaiHao,
                    url: '../Equipment/EquFangShaKind.html?&TaiHao=' + TaiHao + '&EquNo='+EquNo+'&CustomerID=' + CustomerID + '&FangShaKind=' + encodeURIComponent(FangShaKind),
                    width: "400px",
                    height: "250px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].AcceptClick($('#gridTable'));
                    }
                });
            }
        }

        // 设置维护周期
        function btn_maintenance(event) {
            var TaiHao = $("#gridTable").jqGridRowValue("TaiHao");
            var EquNo = $("#gridTable").jqGridRowValue("EquNo");

            console.log(EquNo);
            var MaintenanceCycle = $("#gridTable").jqGridRowValue("MaintenanceCycle");
            var CustomerID = $("#gridTable").jqGridRowValue("CustomerID");
            if (checkedRow(TaiHao)) {
                dialogOpen({
                    id: "Form",
                    title: '设置维护周期--' + TaiHao,
                    url: '../Equipment/EquMaintenanceCycle.html?&TaiHao=' + TaiHao + '&EquNo='+EquNo+'&CustomerID=' + CustomerID + '&MaintenanceCycle=' + MaintenanceCycle,
                    width: "400px",
                    height: "250px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].AcceptClick($('#gridTable'));
                    }
                });
            }
        }

        // 设备维护操作
        function btn_weihu(event) {
            var TaiHao = $("#gridTable").jqGridRowValue("TaiHao");
            var EquNo = $("#gridTable").jqGridRowValue("EquNo");
            var CustomerID = $("#gridTable").jqGridRowValue("CustomerID");
            if (checkedRow(TaiHao)) {
                dialogConfirm("设备维护操作", function (r) {
                    if (r) {
                        Loading(true, "正在删除数据...");

                        window.setTimeout(function () {
                            $.equinfojs.maintenanceEquInfo(TaiHao, EquNo,CustomerID, $('#gridTable'));
                        }, 500);
                    }
                });
            }
        }

        //删除设备信息
        function btn_delete(event) {

            var keyValue = $("#gridTable").jqGridRowValue("ID");
            if (keyValue) {
                dialogConfirm("注：您确定要删除吗？该操作将无法恢复", function (r) {
                    if (r) {
                        Loading(true, "正在删除数据...");

                        window.setTimeout(function () {
                            $.equinfojs.deleteEquInfo(keyValue, $('#gridTable'));
                        }, 500);
                    }
                });
            }
        }

        //读取cookie
        function getCookie(name) {
            var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
            if (arr != null) return decodeURI(arr[2]); return null;
        };

    </script>
</body>
</html>

